<template>
	<view>
		<navigator :url="'/pages/news/detail?id='+item.id" hover-class="none" class="list flex between" v-for="(item,index) in list"
			:key="index">
			<image :src="'https://xsdy.ncscloudmedia.com'+item.cover" mode="aspectFill"></image>
			<view class="info flex wrap">
				<view class="name">{{item.title}}</view>
				<view class="time flex align between">
					<view>{{item.pv}}人阅读</view>
					<view>{{item.create_time}}</view>
				</view>
			</view>
		</navigator>
		<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
	</view>
</template>

<script>
	import {
		articleQuery
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
			};
		},
		onLoad() {
			this.getlist();
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		methods: {
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
				} = that;

				let obj = {
					size: offset,
					page: page + 1,
				};
				that.status = 'loading';
				if (totalPage > page) {
					let result = await articleQuery(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.list {
		padding: 20rpx 26rpx;
		border-bottom: solid 1rpx #DEDEDE;
		background: white;

		image {
			width: 194rpx;
			height: 148rpx;
		}

		.info {
			width: 68%;
		}

		.name {
			font-size: 30rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
			width: 100%;
		}

		.time {
			color: #999999;
			font-size: 22rpx;
			width: 100%;
		}
	}
</style>